/**
 * 
 */
package com.jim.dao;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.jim.to.MiniBlogTO;

/**
 * @author rainman.jin
 *
 */
public class MiniBlogDAO {

	public MiniBlogTO saveMiniBlog(MiniBlogTO blog)
	{
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try
		{
			pm.makePersistent(blog);
		}finally
		{
			//pm.close();
		}
		return blog;
	}
	
	public List<MiniBlogTO> getMiniBlogList(int pageNumber, int itemsPerPage)
	{
		List<MiniBlogTO> blogList = new ArrayList<MiniBlogTO>();
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try
		{
			Query query = pm.newQuery(MiniBlogTO.class);
			query.setRange(pageNumber*itemsPerPage, pageNumber*itemsPerPage+itemsPerPage);
			query.setOrdering("date desc");
			blogList = (List<MiniBlogTO>)query.execute();
		}finally
		{
			pm.close();
		}

		return blogList;
	}
}
